﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Net.Mail;
using System.Net;
using Mc.Fe.WcfService;

namespace Mc.Fe.WcfService
{
    public class EmailService
    {
        public static bool EnviarCorreo(string subject, string body)
        {
            bool retorno = false;
            try
            {
                MailMessage correo = new MailMessage();
                string from = System.Configuration.ConfigurationManager.AppSettings["From"];
                correo.From = new MailAddress(from);

                correo.To.Add(System.Configuration.ConfigurationManager.AppSettings["To"]);
                correo.Subject = subject;
                correo.Body = body;
                correo.IsBodyHtml = false;
                correo.Priority = MailPriority.Normal;

                SmtpClient smtp = new SmtpClient();
                smtp.Credentials = new NetworkCredential();
                //smtp.Credentials = new NetworkCredential(from, "password");

                smtp.Host = System.Configuration.ConfigurationManager.AppSettings["Host"];
                smtp.Port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Port"]);
                smtp.EnableSsl = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["EnableSsl"]);
                smtp.Send(correo);

                retorno = true;
            }
            catch (Exception ex)
            {
                System.Console.Write(ex.Message);
            }
            return retorno;
        }
    }
}